package uitest
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.LoaderMax;
	import com.greensock.loading.SWFLoader;
	import com.greensock.loading.XMLLoader;
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.SharedObject;
	import flash.system.LoaderContext;
	import flash.system.Security;
	import flash.system.SecurityPanel;
	import flash.ui.Mouse;
	import flash.ui.MouseCursor;
	import flash.ui.MouseCursorData;
	import flash.utils.setInterval;
	import flash.utils.setTimeout;
	import iscript.gameFramework.GameLite.Game;
	import iscript.uiFramework.baseShape.Ball;
	import iscript.uiFramework.components.button.BaseButton;
	import iscript.uiFramework.components.container.Box;
	import iscript.uiFramework.components.container.Container;
	import iscript.uiFramework.components.container.ScrollBox;
	import iscript.uiFramework.components.core.Background;
	import iscript.uiFramework.components.core.CursorManager;
	import iscript.uiFramework.components.core.DragManager;
	import iscript.uiFramework.components.core.PopupManager;
	import iscript.uiFramework.components.form.ComboBox;
	import iscript.uiFramework.components.form.NumberInput;
	import iscript.uiFramework.components.form.TextInput;
	import iscript.uiFramework.components.layout.BoxLayout;
	import iscript.uiFramework.components.layout.FlowLayout;
	import iscript.uiFramework.components.layout.LayoutMargin;
	import iscript.uiFramework.components.message.Message;
	import iscript.uiFramework.components.message.MessageButtonConfig;
	import iscript.uiFramework.components.message.MessageButtonType;
	import iscript.uiFramework.components.panel.FramePanel;
	import iscript.uiFramework.components.panel.Panel;
	import iscript.uiFramework.components.panel.PanelHeader;
	import iscript.uiFramework.components.panel.ScrollPanel;
	import iscript.uiFramework.components.silder.SilderPolicy;
	import iscript.uiFramework.components.text.TextWord;
	import iscript.uiFramework.components.toolButton.*;
	import iscript.uiFramework.components.UIComponent;
	import iscript.uiFramework.components.window.Window;
	import iscript.uiFramework.data.ComboBoxModel;
	import iscript.uiFramework.event.ButtonEvent;
	import iscript.uiFramework.event.ComboBoxEvent;
	import iscript.uiFramework.UIFramework;
	import iscript.uiFramework.util.NumberUtil;
	import menuTest.menutest;
	
	import org.flashdevelop.utils.FlashConnect;
	FlashConnect.initialize()
	

	public class Main extends Sprite
	{
		public var loader:LoaderMax
		
		[Embed(source="../../bin/lufei.jpg")]
		private var lufei:Class;
		
		[Embed(source="../../bin/icon/music.png")]
		private var music:Class;
		
		public function Main():void
		{
			
			//stage.displayState = StageDisplayState.FULL_SCREEN;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			var a:int = Number.NaN
			trace(isNaN(a), a)
			
 
			
			
			
			
			
			var game:Game = new Game(stage);
			
			LoaderMax.defaultContext = new LoaderContext(false, stage.loaderInfo.applicationDomain);
			loader = new LoaderMax();
			loader.append(new SWFLoader("UISKin.swf", {name: "UISKINSWF"}));
			loader.append(new XMLLoader("UIResourceSetting.xml", {name: "UISKINXML"}));
			loader.load()
			loader.addEventListener(LoaderEvent.COMPLETE, _initializeUI);
			
			trace("Default Message")
			trace("[Tab0:]", "Custom Message")
		}
		
		private function _initializeUI(e:LoaderEvent):void
		{
			
			var data:XML = XML(XMLLoader(loader.getLoader("UISKINXML")).content)
			var uiFramework:UIFramework = new UIFramework();
			uiFramework.initialize(stage, data);
			
/*			var button:ButtonUITest = new ButtonUITest();
			addChild(button);*/
			var  b:BaseButton = new BaseButton()
			
			b.textLabel.icon = UIFramework.resource.getBitmapData("GameLite.UIComponent.DefaultTheme.Icon.FolderUp");
			//b.text = "iscript";
			//b.flat = true;
			b.render(this)
			
		 
			
			var  framepanel:FramePanel = new FramePanel(500,200);
				// framepanel.append(new BaseButton(), FramePanel.NORTH);
				// framepanel.append(new BaseButton(), FramePanel.WEST);
				 framepanel.append(new BaseButton(), FramePanel.CENTER);
				 framepanel.append(new BaseButton(), FramePanel.EAST);
				 //framepanel.render(this);
				 
				// framepanel.northHeight = 100
				 
				 
				 setTimeout(function():void {
					// removeChild(b);
				//	 framepanel.remove(FramePanel.NORTH)
					 },2000)
			
		/* 	var panel:PanelTest = new PanelTest();
				addChild(panel); 
				
				
				var menu:menutest = new menutest();
			addChild(menu); */
			
			
			// var viewport:viewportTest = new viewportTest()
			//addChild(viewport)
		 
		 //	CursorManager.initialize();
			// CursorManager.setCursor(CursorManager.HResize);
			
		/*	var _cdata:Vector.<BitmapData> = new Vector.<BitmapData>();
			_cdata.push(UIFramework.resource.getBitmapData("GameLite.UIComponent.Cursors.HResize"));
			
			var mousedata:MouseCursorData = new MouseCursorData();
			    mousedata.data = _cdata;
				mousedata.hotSpot = new Point(_cdata[0].width / 2, _cdata[0].height / 2);
				Mouse.registerCursor("angryCursor", mousedata);
				Mouse.cursor = "angryCursor";
			 */
			//	setTimeout(function():void{	 CursorManager.setCursor(CursorManager.VResize)},4000)
				
			 var form:FormUITest = new FormUITest();
				addChild(form) 
			return;
			
		/*	var appBg:Class =  UIFramework.resource.getClass("GameLite.UIComponent.DefaultTheme.Window.ApplicationBackground") ;
			var bg:Sprite = new appBg() as Sprite
 			bg.width = UIFramework.UiStage.stageWidth;
			bg.height = UIFramework.UiStage.stageHeight;
			UIFramework.UiStage.addEventListener(Event.RESIZE, function(e:*):void {
					bg.width = UIFramework.UiStage.stageWidth;
					bg.height = UIFramework.UiStage.stageHeight;
				})
			addChild(bg);*/
			
	 
			var text:TextWord = new TextWord();
			text.text ="Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			+ "Actions let you share handlers, configuration and updates across Toolbar, Button and Menu components."
			text.x = 50;
			text.y = 500;
			text.width = 550;
			text.border = true;
			//text.color = 0xFF0080;
			text.background = true;
			text.mouseChildren = false;
			text.mouseEnabled = false;
			//text.getBackground().begFillColor(0xFFFFFF);
			text.getBackground().begFillColor(0x99BCE8);
			//text.render(this)
			

			
		
			
			var toolbar:ToolBarTest = new ToolBarTest()
			addChild(toolbar)
		
				
			var target0:DisplayObject;
			var target1:DisplayObject;
			
		
			
			for (var i:int = 0; i < 2; i++)
			{
				
				var window:Window = new Window("window-" + i);
				if (i == 1)
				{
					window.dialog = true;
					//window.dialogVisible = false;
					window.body.append(new lufei())
					window.body.processWidth=0.45
				//	PopupManager.keepTop(window);
					target1 = window;					
					Window(target1).width = 600;
					Window(target1).height = 400;
					
					window.x =  UIFramework.UiStage.stageWidth * 0.5 -  window.width * 0.5;
					window.y =  UIFramework.UiStage.stageHeight * 0.5 -  window.height * 0.5;
					
				}
				else
				{
					target0 = window;
					window.x = 50
					window.y=350
				}
				PopupManager.append(window);
				DragManager.add(window);
					//setTimeout(function():void {PopupManager.append(window);},Math.random()*3*1000)
			}
			
			var nw:NewWindow = new NewWindow();
			nw.shadow = true;
				PopupManager.append(nw);
				DragManager.add(nw);
				
			 setTimeout(function():void { nw.close() }, 5 * 1000);
			
			// PopupManager.keepTop(window);
			/*	 DragManager.remove(target);*/
			setTimeout(function():void
				{
					//PopupManager.keepTop(null);
					 Window(target1).body.clear();
				// PopupManager.keepTop(Window(target0));
				}, 2000)
 
			var ni:NumberInput = new NumberInput();
			ni.x = 450;
			ni.y = 350;
			
			ni.minValue = 0
			ni.maxValue = 10
			ni.stepValue = 1
			ni.value = 2
			//ni.width=150
			ni.render(this);
			
			var msgButCg:MessageButtonConfig = new MessageButtonConfig();
				msgButCg.YesButtonText = "确定"
				msgButCg.YesButtonHandler = function():void{trace("YES")}
				msgButCg.type = MessageButtonType.YESNO;
		
			var msg:Message = new Message();			
			msg.title = "message box"
			msg.text ="message box test"
			msg.messageButtonConfig = msgButCg;
			msg.render();
			
			 
		 
				
		}
	
	}
}
